import { defineStore } from 'pinia'
import useCounterStore from './counter'

// 返回一个函数, 该函数将来可以用于获取仓库
const useUserStore = defineStore('user', {
  state() {
    return {
      name: '张三',
      age: 19,
    }
  },

  actions: {
    changeName() {
      this.name = '李四'

      // 需求: 还需要跨模块, 去修改counter模块count
      // 如何在模块中 获取别的模块
      const counter = useCounterStore()
      counter.addOne()
    },

    addAgeAsync() {
      setTimeout(() => {
        this.age++
      }, 1000)
    },
  },
  getters: {
    doubleAge() {
      return this.age * 2
    },
  },
})

export default useUserStore
